package com.hzit.search.config;


import co.elastic.clients.elasticsearch.ElasticsearchClient;
import co.elastic.clients.json.jackson.JacksonJsonpMapper;
import co.elastic.clients.transport.ElasticsearchTransport;
import co.elastic.clients.transport.rest_client.RestClientTransport;
import com.hzit.search.properties.ElasticsearchProperties;
import org.apache.http.HttpHost;
import org.elasticsearch.client.RestClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * 类名：
 * 作者：WF
 * 功能：
 */
@Configuration
public class ElasticsearchConfig {
	@Autowired
	private ElasticsearchProperties properties;
	@Bean
	public ElasticsearchClient elasticsearchClient(){
		System.out.println("properties = " + properties);
		RestClient restClient = RestClient.builder(new HttpHost(properties.getHost(),properties.getPort())).build();
		ElasticsearchTransport transport = new RestClientTransport(
				restClient, new JacksonJsonpMapper());
		return new ElasticsearchClient(transport);
	}
}
